//
//  ViewController.m
//  TouchIDDemo
//
//  Created by HaiSheng on 15/7/15.
//  Copyright (c) 2015年 huanghaisheng. All rights reserved.
//

#import "ViewController.h"
#import <LocalAuthentication/LocalAuthentication.h>

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    [self touchIDFunction];
    
//    [self prepareForSegue:<#(UIStoryboardSegue *)#> sender:<#(id)#>];
//    [self performSegueWithIdentifier:<#(NSString *)#> sender:<#(id)#>]
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)touchIDFunction {
    
    
    LAContext *authenticationContext = [[LAContext alloc] init];
    authenticationContext.maxBiometryFailures = @5;
    NSError *authError = nil;
    
    if ([authenticationContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&authError]) {
        
        [authenticationContext evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics
                  localizedReason:@"通过Home键验证已有手机指纹"
                            reply:^(BOOL success, NSError *error) {
                                if (success) {
                                    // User authenticated successfully, take appropriate action
                                    NSLog(@"指纹认证成功！");
                                } else {
                                    // User did not authenticate successfully, look at error and take appropriate action
                                    NSLog(@"指纹认证失败！error:%@", error);
                                }
                            }];
    } else {
         // Could not evaluate policy; look at authError and present an appropriate message to user
        NSLog(@"设备不支持指纹认证");
    }
    
}




@end
